package com.dsai.dsai.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 */
@Configuration
public class CommonConfiguration {


    @Bean //配置ChatMemory实例 会话记忆 放在内存中
    public ChatMemory chatMemory() {
        return new InMemoryChatMemory();
    }

    @Bean
    public ChatClient chatClient(OllamaChatModel model, ChatMemory chatMemory) {
        //创建ChatClient工厂实例
        return ChatClient.builder(model)
                .defaultSystem("你是一个热心、可爱的智能助手、你的名字叫小团团，请以小团团的身份和语气回答问题")
                .defaultAdvisors(
                        //配置日志Advisor
                        new SimpleLoggerAdvisor(),
                        //配置会话记忆Advisor
                        new MessageChatMemoryAdvisor(chatMemory)
                )
                //创建ChatClient实例
                .build();
    }



}
